﻿<?php
	class Economic{
	
		private $name;
		private $value;
		private $unit;
		private $id;
		private $year;
		private $month;
		
		function __construct(){
			$this->conn = conn();
		}	

		public function listAll(){		
			$query = "select * from Economic";
			$stmt = $this->conn->query( $query ); 
			$items = array();
			while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) { 
				$id = $row['ID'];
				$name = $row['Name'];
				$value = $row['Value'];
				$unit = $row['Unit'];
				$year = $row['Year'];
				$month = $row['Month'];
				$item=array("id"=>$id,"name"=>$name,"value"=>$value,"unit"=>$unit,"year"=>$year,"month"=>$month);
				array_push($items, $item);
			}				
			return $items;
		}
		
		public function update($item){
		
			$id = $item['id'];
			$name = $item['name'];
			$value = $item['value'];
			$unit = $item['unit'];
			$year = $item['year'];
			$month = $item['month'];
			$query = "update Economic SET Name ='".$name."', Value = '".$value."', Unit = '".$unit."', Year = '".$year."', Month = '".$month."' where ID = '".$id."'";
			echo $query;
			
			$stmt = $this->conn->query( $query );
		}		
		
		public function insert($item){			
			$id = $item['ID'];
			$name = $item['name'];
			$value = $item['value'];
			$unit = $item['unit'];	
			$year = $item['year'];
			$month = $item['month'];
			$query = "INSERT INTO Economic(Name,Year,Month,Value,Unit) VALUES('".$name."','".$year."','".$month."','".$value."','".$unit."')";
			//print_r ($query);
			$stmt = $this->conn->query( $query );
		}	
		
		public function delete($id){
			$query = "delete from Economic where ID = '".$id."'";
			$stmt = $this->conn->query( $query );
		}
		
		public function getById($id){		
			$query = "select * from Economic where ID = '".$id."'";
			$stmt = $this->conn->query( $query );
			$row = $stmt->fetch( PDO::FETCH_ASSOC );
			$id = $row['ID'];
			$name = $row['Name'];
			$value = $row['Value'];
			$unit = $row['Unit'];
			$year = $row['Year'];
			$month = $row['Month'];
			$item=array("id"=>$id,"name"=>$name,"value"=>$value,"unit"=>$unit,"year"=>$year,"month"=>$month);
			return $item;
		}
		
	}
?>